home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / src / pt-cmd.h < prev    next >
C/C++ Source or Header  |  1997-03-07  |  9KB  |  409 lines

  1. /*
  2.  
  3. Copyright (C) 1996 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. #if !defined (octave_tree_cmd_h)
  24. #define octave_tree_cmd_h 1
  25.  
  26. #if defined (__GNUG__)
  27. #pragma interface
  28. #endif
  29.  
  30. class ostream;
  31.  
  32. class octave_value_list;
  33.  
  34. class tree_statement_list;
  35. class tree_global_init_list;
  36. class tree_if_command_list;
  37. class tree_switch_case_list;
  38. class tree_expression;
  39. class tree_index_expression;
  40. class tree_identifier;
  41. class tree_return_list;
  42. class octave_value;
  43. class symbol_record;
  44.  
  45. class tree_command;
  46. class tree_global_command;
  47. class tree_while_command;
  48. class tree_for_command;
  49. class tree_if_command;
  50. class tree_switch_command;
  51. class tree_try_catch_command;
  52. class tree_unwind_protect_command;
  53. class tree_no_op_command;
  54. class tree_break_command;
  55. class tree_continue_command;
  56. class tree_return_command;
  57.  
  58. class tree_walker;
  59.  
  60. #include <string>
  61.  
  62. #include "pt-base.h"
  63.  
  64. // A base class for commands.
  65.  
  66. class
  67. tree_command : public tree
  68. {
  69. public:
  70.  
  71.   tree_command (int l = -1, int c = -1) : tree (l, c) { }
  72.  
  73.   virtual ~tree_command (void) { }
  74.  
  75.   virtual void eval (void) = 0;
  76. };
  77.  
  78. class
  79. tree_global_command : public tree_command
  80. {
  81. public:
  82.  
  83.   tree_global_command (int l = -1, int c = -1)
  84.     : tree_command (l, c), init_list (0) { }
  85.  
  86.   tree_global_command (tree_global_init_list *t, int l = -1, int c = -1)
  87.     : tree_command (l, c), init_list (t) { }
  88.  
  89.   ~tree_global_command (void);
  90.  
  91.   void eval (void);
  92.  
  93.   tree_global_init_list *initializer_list (void) { return init_list; }
  94.  
  95.   void accept (tree_walker& tw);
  96.  
  97. private:
  98.  
  99.   // The list of global variables or initializers in this global
  100.   // command.
  101.   tree_global_init_list *init_list;
  102. };
  103.  
  104. // While.
  105.  
  106. class
  107. tree_while_command : public tree_command
  108. {
  109. public:
  110.  
  111.   tree_while_command (int l = -1, int c = -1)
  112.     : tree_command (l, c), expr (0), list (0) { }
  113.  
  114.   tree_while_command (tree_expression *e, int l = -1, int c = -1)
  115.     : tree_command (l, c), expr (e), list (0) { }
  116.  
  117.   tree_while_command (tree_expression *e, tree_statement_list *lst,
  118.               int l = -1, int c = -1)
  119.     : tree_command (l, c), expr (e), list (lst) { }
  120.  
  121.   ~tree_while_command (void);
  122.  
  123.   void eval (void);
  124.  
  125.   void eval_error (void);
  126.  
  127.   tree_expression *condition (void) { return expr; }
  128.  
  129.   tree_statement_list *body (void) { return list; }
  130.  
  131.   void accept (tree_walker& tw);
  132.  
  133. private:
  134.  
  135.   // Expression to test.
  136.   tree_expression *expr;
  137.  
  138.   // List of commands to execute.
  139.   tree_statement_list *list;
  140. };
  141.  
  142. // For.
  143.  
  144. class
  145. tree_for_command : public tree_command
  146. {
  147. public:
  148.  
  149.   tree_for_command (int l = -1, int c = -1)
  150.     : tree_command (l, c), id (0), id_list (0), expr (0), list (0) { }
  151.  
  152.   tree_for_command (tree_index_expression *ident, tree_expression *e,
  153.             tree_statement_list *lst, int l = -1, int c = -1)
  154.     : tree_command (l, c), id (ident), id_list (0), expr (e),
  155.       list (lst) { }
  156.  
  157.   tree_for_command (tree_return_list *ident, tree_expression *e,
  158.             tree_statement_list *lst, int l = -1, int c = -1)
  159.     : tree_command (l, c), id (0), id_list (ident), expr (e),
  160.       list (lst) { }
  161.  
  162.   ~tree_for_command (void);
  163.  
  164.   void eval (void);
  165.  
  166.   void eval_error (void);
  167.  
  168.   tree_index_expression *ident (void) { return id; }
  169.  
  170.   tree_expression *control_expr (void) { return expr; }
  171.  
  172.   tree_statement_list *body (void) { return list; }
  173.  
  174.   void accept (tree_walker& tw);
  175.  
  176. private:
  177.  
  178.   // Identifier to modify.
  179.   tree_index_expression *id;
  180.  
  181.   // List of identifiers to modify.
  182.   tree_return_list *id_list;
  183.  
  184.   // Expression to evaluate.
  185.   tree_expression *expr;
  186.  
  187.   // List of commands to execute.
  188.   tree_statement_list *list;
  189.  
  190.   void do_for_loop_once (tree_return_list *lst,
  191.              const octave_value_list& rhs, bool& quit);
  192.  
  193.   void do_for_loop_once (tree_index_expression *idx_expr,
  194.              const octave_value& rhs, bool& quit);
  195.  
  196.   void do_for_loop_once (tree_identifier *ident,
  197.              octave_value& rhs, bool& quit);
  198. };
  199.  
  200. // If.
  201.  
  202. class
  203. tree_if_command : public tree_command
  204. {
  205. public:
  206.  
  207.   tree_if_command (int l = -1, int c = -1)
  208.     : tree_command (l, c), list (0) { }
  209.  
  210.   tree_if_command (tree_if_command_list *lst, int l = -1, int c = -1)
  211.     : tree_command (l, c), list (lst) { }
  212.  
  213.   ~tree_if_command (void);
  214.  
  215.   void eval (void);
  216.  
  217.   tree_if_command_list *cmd_list (void) { return list; }
  218.  
  219.   void accept (tree_walker& tw);
  220.  
  221. private:
  222.  
  223.   // List of if commands (if, elseif, elseif, ... else, endif)
  224.   tree_if_command_list *list;
  225. };
  226.  
  227. // Switch.
  228.  
  229. class
  230. tree_switch_command : public tree_command
  231. {
  232. public:
  233.  
  234.   tree_switch_command (int l = -1, int c = -1)
  235.     : tree_command (l, c), expr (0), list (0) { }
  236.  
  237.   tree_switch_command (tree_expression *e, tree_switch_case_list *lst,
  238.                int l = -1, int c = -1)
  239.     : tree_command (l, c), expr (e), list (lst) { }
  240.  
  241.   ~tree_switch_command (void);
  242.  
  243.   void eval (void);
  244.  
  245.   void eval_error (void);
  246.  
  247.   tree_expression *switch_value (void) { return expr; }
  248.  
  249.   tree_switch_case_list *case_list (void) { return list; }
  250.  
  251.   void accept (tree_walker& tw);
  252.  
  253. private:
  254.  
  255.   // Value on which to switch.
  256.   tree_expression *expr;
  257.  
  258.   // List of cases (case 1, case 2, ..., default)
  259.   tree_switch_case_list *list;
  260. };
  261.  
  262. // Simple exception handling.
  263.  
  264. class
  265. tree_unwind_protect_command : public tree_command
  266. {
  267. public:
  268.  
  269.   tree_unwind_protect_command (int l = -1, int c = -1)
  270.     : tree_command (l, c), unwind_protect_code (0), cleanup_code (0) { }
  271.  
  272.   tree_unwind_protect_command (tree_statement_list *tc,
  273.                    tree_statement_list *cc,
  274.                    int l = -1, int c = -1)
  275.     : tree_command (l, c), unwind_protect_code (tc), cleanup_code (cc) { }
  276.  
  277.   ~tree_unwind_protect_command (void);
  278.  
  279.   void eval (void);
  280.  
  281.   tree_statement_list *body (void) { return unwind_protect_code; }
  282.  
  283.   tree_statement_list *cleanup (void) { return cleanup_code; }
  284.  
  285.   void accept (tree_walker& tw);
  286.  
  287. private:
  288.  
  289.   // The first body of code to attempt to execute.
  290.   tree_statement_list *unwind_protect_code;
  291.  
  292.   // The body of code to execute no matter what happens in the first
  293.   // body of code.
  294.   tree_statement_list *cleanup_code;
  295. };
  296.  
  297. // Simple exception handling.
  298.  
  299. class
  300. tree_try_catch_command : public tree_command
  301. {
  302. public:
  303.  
  304.   tree_try_catch_command (int l = -1, int c = -1)
  305.     : tree_command (l, c), try_code (0), catch_code (0) { }
  306.  
  307.   tree_try_catch_command (tree_statement_list *tc,
  308.                    tree_statement_list *cc,
  309.                    int l = -1, int c = -1)
  310.     : tree_command (l, c), try_code (tc), catch_code (cc) { }
  311.  
  312.   ~tree_try_catch_command (void);
  313.  
  314.   void eval (void);
  315.  
  316.   tree_statement_list *body (void) { return try_code; }
  317.  
  318.   tree_statement_list *cleanup (void) { return catch_code; }
  319.  
  320.   void accept (tree_walker& tw);
  321.  
  322. private:
  323.  
  324.   // The first block of code to attempt to execute.
  325.   tree_statement_list *try_code;
  326.  
  327.   // The code to execute if an error occurs in the first block.
  328.   tree_statement_list *catch_code;
  329. };
  330.  
  331. // No-op.
  332.  
  333. class
  334. tree_no_op_command : public tree_command
  335. {
  336. public:
  337.  
  338.   tree_no_op_command (const string& cmd = "no_op", int l = -1, int c = -1)
  339.     : tree_command (l, c), orig_cmd (cmd) { }
  340.  
  341.   ~tree_no_op_command (void) { }
  342.  
  343.   void eval (void) { }
  344.  
  345.   void accept (tree_walker& tw);
  346.  
  347.   string original_command (void) { return orig_cmd; }
  348.  
  349. private:
  350.  
  351.   string orig_cmd;
  352. };
  353.  
  354. // Break.
  355.  
  356. class
  357. tree_break_command : public tree_command
  358. {
  359. public:
  360.  
  361.   tree_break_command (int l = -1, int c = -1) : tree_command (l, c) { }
  362.  
  363.   ~tree_break_command (void) { }
  364.  
  365.   void eval (void);
  366.  
  367.   void accept (tree_walker& tw);
  368. };
  369.  
  370. // Continue.
  371.  
  372. class
  373. tree_continue_command : public tree_command
  374. {
  375. public:
  376.  
  377.   tree_continue_command (int l = -1, int c = -1) : tree_command (l, c) { }
  378.  
  379.   ~tree_continue_command (void) { }
  380.  
  381.   void eval (void);
  382.  
  383.   void accept (tree_walker& tw);
  384. };
  385.  
  386. // Return.
  387.  
  388. class
  389. tree_return_command : public tree_command
  390. {
  391. public:
  392.  
  393.   tree_return_command (int l = -1, int c = -1) : tree_command (l, c) { }
  394.  
  395.   ~tree_return_command (void) { }
  396.  
  397.   void eval (void);
  398.  
  399.   void accept (tree_walker& tw);
  400. };
  401.  
  402. #endif
  403.  
  404. /*
  405. ;;; Local Variables: ***
  406. ;;; mode: C++ ***
  407. ;;; End: ***
  408. */
  409.